package or;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class T0099 {
    List<String> list;
    String strb;

    public List<String> restoreIpAddresses(String s) {
        list = new ArrayList<>();
        strb = "";
        restoreIpAddressesHelp(s, 0, 1);
        return list;
    }

    public void restoreIpAddressesHelp(String s, int indix, int n) {
        if (n == 5 && indix == s.length()) {
            list.add(strb.substring(0,strb.length()-1));
            return;
        }
        if (n == 5 || indix == s.length()) return;
        for (int i = 0; i < 3 && indix + i < s.length(); i++) {
            String s1 = s.substring(indix, indix + i + 1);
            if (s.charAt(indix) != '0' && Integer.parseInt(s1) <= 255 || i == 0) {
                strb = strb + s1 + ".";
                restoreIpAddressesHelp(s, indix + i + 1, n + 1);
                strb = strb.substring(0, indix + n - 1);
            }
        }
    }

    @Test
    public void test() {
        System.out.println(restoreIpAddresses("101023").toString());
    }
}
